package top.letscode.adclicker.ad;

import top.letscode.adclicker.util.RandomUtil;
import top.letscode.adclicker.util.Utils;

public class AdRuleChecker {

  /**
   * 凌晨2~6点的点击概率减少为1/3
   */
  private static float computeRate(AbstractUnion union) {
    if (Utils.isInMorning()) {
      return union.getRate() / 3;
    }

    return union.getRate();
  }

  /**
   * 根据设定的概率，检测当前是否允许点击。带有随机性
   */
  public static boolean canClick(AbstractUnion union) {
    return RandomUtil.randomFloat() < computeRate(union);
  }
}
